Registers of ADC in LPC2148 Microcontroller
1. AD0CR (ADC0 Control Register)
Bits 7:0 – SEL
Bits 15:8 – CLKDIV
Bit 16 – BURST
Bits 19:17 – CLKS
Bit 26:24 – START
Bit 27 – EDGE
2. AD0GDR (ADC0 Global Data Register)
Bits 15:6 – RESULT
Bits 26:24 – CHN
Bit 30 – Overrun
Bit 31 – DONE
Bit 31 – DONE
3. ADGSR (A/D Global Start Register)
BURST (Bit 16), START (Bit <26:24>) & EDGE (Bit 27)
4. AD0STAT (ADC0 Status Register)
Bit 7:0 – DONE7:DONE0
Bit 15:8 – OVERRUN7:OVERRUN0
Bit 16 – ADINT
5. AD0INTEN (ADC0 Interrupt Enable)
Bit 0 – ADINTEN0
Bit 8 – ADGINTEN
6. AD0DR0-AD0DR7 (ADC0 Data Registers)
Bits 15:6 – RESULT
Bit 30 – Overrun
Bit 31 – DONE
Programming Steps: ADC in LPC2148 ARM7 Microcontroller
/* Name : main.c * Purpose : Source code for ADC Interfacing with ARM LPC1248. * Author : Gemicates * Date : 2018-09-02 * Website : www.gemicates.org * Revision : None */ #include<lpc214x.h> // header file for LPC21XX series #define LCD (0xff<<16) #define RS (1<<13) // register select pin #define RW (1<<14) // read write pin #define EN (1<<15) // enable pin void delay_fv(unsigned int x,int y); void lcd_display(unsigned int x); void cmd(unsigned char m); void lcd_ini(); void lcd_pos(int line, int pos); void lcd_str(unsigned char *x); void adc_ini(); unsigned long int adc_data(); int main() { unsigned long temp; unsigned char first,second,third,fourth; PINSEL0=0X00000000; // select PORT0 as GPIO mode IO0DIR=0XFFFFFFFF; // make PORT0 pin as Output mode adc_ini(); lcd_ini(); lcd_str("TEMP VALUE IS"); lcd_pos(2,6); lcd_display('C'); while(1) // Repeat(loop) forever { temp=adc_data(); temp=temp*3300; temp=temp/1023; first=temp%10+'0'; temp=temp/10; second=temp%10+'0'; temp=temp/10; third=temp%10+'0'; temp=temp/10; fourth=temp%10+'0'; temp=temp/10; lcd_pos(2,0); lcd_display(fourth); lcd_display(third); lcd_display(second); lcd_display('.'); lcd_display(first); } } void delay_fv(unsigned int x,int y) // Time delay function in milli seconds { unsigned int i,j; for(i=0;i<x;i++) for(j=0;j<y;j++); } void lcd_display(unsigned int x) // Function to send data to LCD { IO0CLR|=(RS|RW|EN|LCD); IO0SET|=(x<<16); IO0SET|=RS; IO0CLR|=RW; IO0SET|=EN; delay_fv(100,200); IO0CLR|=EN; delay_fv(10,10); } void cmd(unsigned char m) // Function to send command to LCD { IO0CLR|=(RS|RW|EN|LCD); IO0SET|=(m<<16); IO0CLR|=RS; IO0CLR|=RW; IO0SET|=EN; delay_fv(100,10); IO0CLR|=EN; delay_fv(100,10); } void lcd_ini() // Funtion to Initialize LCD { cmd(0X38); // for using 8-bit 2 row mode and 5x7 Dots of LCD cmd(0X0C); // turn display ON for cursor OFF cmd(0X06); // display ON cmd(0X01); // clear screen cmd(0X80); // clear screen } void lcd_pos(int line, int pos) // Function to select the position in LCD { if(line==1) cmd(0x80+pos); else if(line==2) cmd(0xc0+pos); } void lcd_str(unsigned char *x) // Function to display in LCD { while(*x!='\0') { lcd_display(*x); x++; } } void adc_ini() { AD0CR = 1<<21; // A/D is Operational AD0CR = 0<<21; // A/D is in Power Down Mode PINSEL1 = 0x01000000; // P0.28 is Configured as Analog to Digital Converter Pin AD0.1 AD0CR = 0x00200802; // CLKDIV=4,Channel-0.1 Selected,BURST=0,EDGE=0 } unsigned long int adc_data() { unsigned long rec; AD0CR |= (1<<24); // Start Conversion while(!(AD0GDR & 0x80000000)); /*Wait untill the DONE bits Sets*/ rec = AD0GDR; AD0CR &= ~0x01000000; // Stops the A/D Conversion rec = rec >> 6; // data is present after 6 bit rec = rec & 0x3FF; // Clearing all other Bits return (rec); }